package com.yuma.mediator;

import java.util.ArrayList;
import java.util.List;

public class ChatServer {
    private List<ChatUser> chatUsers = new ArrayList<>();

    public void join(ChatUser chatUser) {
        chatUsers.add(chatUser);
    }

    public void remove(ChatUser chatUser){
        if (chatUsers.contains(chatUser)){
            chatUsers.remove(chatUser);
        }
    }

    // 群发
    public void sendToUser(String message){
        for (ChatUser chatUser : chatUsers) {
            chatUser.receive(message);
        }
    }

}
